package com.tanhua.dubbo.api.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tanhua.domain.db.BlackList;
import com.tanhua.domain.db.UserInfo;
import com.tanhua.dubbo.api.BlackListApi;
import com.tanhua.dubbo.mapper.BlackListMapper;
import com.tanhua.dubbo.mapper.UserInfoMapper;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

@Service
public class BlackListApiImpl implements BlackListApi {

    @Autowired
    private UserInfoMapper userInfoMapper;
    @Autowired
    private BlackListMapper blackListMapper;

    @Override
    public IPage<UserInfo> findByPage(Long userId, Integer page, Integer pagesize) {
        //封装分页参数
        IPage<UserInfo> iPage = new Page<>(page,pagesize);
        //分页查询
        return userInfoMapper.findByPage(iPage,userId);
    }

    @Override
    public void delete(Long userId, Long blackUserId) {
        // 删除的SQL: DELETE FROM tb_black_list WHERE user_id=7 AND black_user_id=8
        // 构造条件
        QueryWrapper<BlackList> wrapper = new QueryWrapper<>();
        wrapper.eq("user_id",userId);
        wrapper.eq("black_user_id",blackUserId);
        blackListMapper.delete(wrapper);
    }
}
